package com.tsvetanv.data.binding.property.editors;

import java.net.MalformedURLException;
import java.net.URL;

import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.bind.ServletRequestDataBinder;

import com.tsvetanv.data.binding.model.property.editors.defaulted.MultitypeCommandBean;

import junit.framework.TestCase;

public class MultitypeCommandBeanBindTest extends TestCase {

	MultitypeCommandBean bean;
	ServletRequestDataBinder binder;
	MockHttpServletRequest request;

	@Override
	protected void setUp() throws Exception {
		bean = new MultitypeCommandBean();
		binder = new ServletRequestDataBinder(bean, "beanName");
		request = new MockHttpServletRequest();
	}

	public void testMiltitypeCommandBeanBind() throws Exception {
		request.addParameter("intProperty", "6");
		request.addParameter("integerProperty", "42");
		request.addParameter("classProperty", "java.net.URL");
		request.addParameter("urlProperty", "http://tsvetanv.com");
		request.addParameter("charProperty", "z");
		request.addParameter("characterProperty", "?");

		binder.bind(request);

		assertEquals(6, bean.getIntProperty());
		assertEquals(new Integer(42), bean.getIntegerProperty());
		assertEquals(URL.class, bean.getClassProperty());
		assertEquals(new URL("http://tsvetanv.com"), bean.getUrlProperty());
		assertEquals('z', bean.getCharProperty());
		assertEquals(new Character('?'), bean.getCharacterProperty());
	}

}
